$(function() {
	$('.Pm_info dl').each(function() {
		var h = replace_em($(this).find('dd').html());
		$(this).find('dd').html(h);

		$(this).find('dt a').click(function() {
			var mid = $(this);
			$.post("mailBoxAjax_deleteMessageById", {
				"message.id" : mid.attr('href')
			}, function(data) {
				if (data != "true") {
					art.dialog.alert('发生未知错误！！！').time(2);
				} else {
					mid.parent().parent().remove();
				}
			});
			return false;
		});

	});
	$('.showIconBtn').qqFace({
		assign : 'saytext',
		path : 'images/arclist/'	//表情存放的路径
	});

	$(".sendMail").click(function() {
		sendMessage();
		return false;
	});
	$("#saytext").keypress(function(event) {
		if (event.keyCode == 10) {
			sendMessage();
		};
	});
	function sendMessage() {
		var str = $("#saytext").val();
		//$("#show").html(replace_em(str));
		var time = (new Date()).Format("yyyy-MM-dd h:mm:ss");
		$.post("mailBoxAjax_addMessage", {
			"message.receiverUser" : $("#sendUserId").val(),
			"message.content" : $("#saytext").val(),
			"otherData['time']" : time
		}, function(data) {
			if (data != "true") {
				art.dialog.alert('发生未知错误！！！').time(2);
			} else {
				var htm = '<dl class="msg_item girl first fireFlowerFlg"><dt>';
				htm += '<font>我</font>';
				htm += '<span>' + time + '</span>';
				htm += '</dt><dd>' + replace_em($("#saytext").val()) + '</dd></dl>';
				$('.Pm_info').append(htm);
				$("#saytext").val("");
			}
		});
	}


	$('.setAttention').click(function() {
		$.post("mailBoxAjax_follow", {
			"luck.value1" : $('#sendUserId').val()
		}, function(data) {
			if (data != "true") {
				art.dialog.alert('发生未知错误！！！').time(2);
			} else {
				art.dialog.alert('关注成功').time(2);
			}
		});
		return false;
	});

});
//查看结果
function replace_em(str) {
	str = str.replace(/\</g, '&lt;');
	str = str.replace(/\>/g, '&gt;');
	str = str.replace(/\n/g, '<br/>');
	str = str.replace(/\[em_([0-9]*)\]/g, '<img src="images/arclist/$1.gif" border="0" />');
	return str;
}

Date.prototype.Format = function(fmt) {//author: meizz
	var o = {
		"M+" : this.getMonth() + 1, //月份
		"d+" : this.getDate(), //日
		"h+" : this.getHours(), //小时
		"m+" : this.getMinutes(), //分
		"s+" : this.getSeconds(), //秒
		"q+" : Math.floor((this.getMonth() + 3) / 3), //季度
		"S" : this.getMilliseconds() //毫秒
	};
	if (/(y+)/.test(fmt))
		fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
	for (var k in o)
	if (new RegExp("(" + k + ")").test(fmt))
		fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
	return fmt;
};
